/*
 * 权限接口
 * @Description: jishupu-admin-template
 * @Author: 技术铺<jishupu@qq.com>
 * @Date: 2021-11-15
 */
import request from '@/utils/request'

/**
 * 列表
 * @param {Object} params
 * @param {Object} extendConfig
 * @returns  new Promise
 */
export function index(params, extendConfig) {
  return request.get('/v1/permission', { params, ...extendConfig })
}

/**
 * 添加
 * @param {Object} params
 * @param {Object} extendConfig
 * @returns  new Promise
 */
export function store(params, extendConfig) {
  return request.post('/v1/permission', params, extendConfig)
}

/**
 * 查看
 * @param {Number} id 权限标识
 * @param {Object} extendConfig
 * @returns  new Promise
 */
export function show(id, extendConfig) {
  return request.get('/v1/permission/' + id, extendConfig)
}

/**
 * 修改
 * @param {Number} id 权限标识
 * @param {Object} params
 * @param {Object} extendConfig
 * @returns  new Promise
 */
export function update(id, params, extendConfig) {
  return request.put(`/v1/permission/${id}`, params, extendConfig)
}

/**
 * 删除
 * @param {Number} id 权限标识
 * @param {Object} extendConfig
 * @returns  new Promise
 */
export function destory(id, extendConfig) {
  return request.delete(`/v1/permission/${id}`, extendConfig)
}

/**
 * 更新状态
 * @param {Number} id 权限标识
 * @param {Object} params 参数如：{ status: 0 }
 * @param {Object} extendConfig
 * @returns  new Promise
 */
export function updateStatus(id, params, extendConfig) {
  return request.patch(`/v1/permission/${id}/status`, params, extendConfig)
}

/**
 * 更新排序
 * @param {Object} params 参数如：{sort: [{id: 7, sort: 2}, {id: 8, sort: 1}]}
 * @param {Object} extendConfig
 * @returns  new Promise
 */
export function updateSort(params, extendConfig) {
  return request.put(`/v1/permission/sort`, params, extendConfig)
}

/**
 * 批量添加
 * @param {Object} extendConfig
 * @returns  new Promise
 */
export function patchStore(extendConfig) {
  return request.post('/v1/permission/patch-store', {}, extendConfig)
}

/**
 * 获取菜单模块等所需权限树数据
 * @returns  new Promise
 */
export function getMenuPermissionTreeConfig() {
  return request.get(`/v1/permission/menu-permission-tree-config`)
}
